package org.xcorpio.java8.chapter06;

import java.util.Comparator;
import java.util.IntSummaryStatistics;
import java.util.Optional;
import java.util.stream.Collectors;

import org.xcorpio.java8.common.Data;
import org.xcorpio.java8.common.Dish;

public class ReducingAndSummarizing {

    public static void main(String[] args) {
        Long howManyDishes = Data.Menu.stream().collect(Collectors.counting());
        System.out.println(howManyDishes);
        Comparator<Dish> dishCaloriesComparator = Comparator.comparingInt(Dish::getCalories);
        Optional<Dish> mostCalorieDish = Data.Menu.stream().collect(Collectors.maxBy(dishCaloriesComparator));
        System.out.println(mostCalorieDish);
        System.out.println(Data.Menu.stream().max(dishCaloriesComparator));

        IntSummaryStatistics totalCalories = Data.Menu.stream().collect(Collectors.summarizingInt(Dish::getCalories));
        System.out.println(totalCalories);
        
        double avgCalories = Data.Menu.stream().collect(Collectors.averagingInt(Dish::getCalories));
        System.out.println(avgCalories);
    }
}
